import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutterproject/mvvm/base/base_state.dart';
import 'package:flutterproject/page/mine/children/order/children/logistics_tracking/logistics_tracking_page.dart';
import 'package:flutterproject/page/mine/children/order/children/order_detail/controller/order_detail_controller.dart';
import 'package:flutterproject/util/dialog_toast/toast_util.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/extension/widget_extension.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/app_bar_common.dart';
import 'package:flutterproject/widget/image_extended.dart';
import 'package:flutterproject/widget/text/text_common.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';

class OrderDetailPage extends BaseState<OrderDetailController> {
  @override
  OrderDetailController initController() => OrderDetailController();

  @override
  Widget initView(BuildContext context) {
    return ColoredBox(
      color: Color(0xFFF6F6F6),
      child: Column(
        children: [
          AppBarCommon(
            title: "订单详情",
            bgColor: Color(0xFFEDC88B),
            leftColor: Colors.white,
            titleColor: Colors.white,
          ),
          Container(
            width: Get.width,
            margin: MarginPaddingUtil.fromLTRB(
                left: 23, top: 28, right: 17, bottom: 20),
            padding: MarginPaddingUtil.fromLTRB(
                left: 37, top: 32, right: 36, bottom: 37),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(20.radius),
            ),
            child: Column(
              children: [
                Row(
                  children: [
                    Spacer(),
                    TextCommon(
                      controller
                          .getStatusStr(controller.orderDetailBean?.state),
                      size: 24.sp,
                      lineHeight: 35.sp,
                      color: controller.orderDetailBean?.state == 3
                          ? Color(0xFFA8A8A8)
                          : Color(0xFFEDC88B),
                    ),
                  ],
                ),
                18.heightBox,
                Row(
                  children: [
                    ImageCommon(
                      "/image/${controller.orderDetailBean?.productTag}_1",
                      size: 128.width,
                      circular: 30.radius,
                    ),
                    32.widthBox,
                    Expanded(
                      child: Column(
                        children: [
                          Row(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              TextCommon(
                                controller.orderDetailBean?.productName ?? "",
                                size: 28.sp,
                                lineHeight: 40.sp,
                              ),
                              Spacer(),
                              TextCommon(
                                "${controller.orderDetailBean?.totalAmount ?? "0.00"}",
                                size: 28.sp,
                                lineHeight: 40.sp,
                                color: Color(0xFFE04D4D),
                                fontWeight: FontWeight.bold,
                              ),
                            ],
                          ),
                          12.heightBox,
                          Row(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Expanded(
                                child: TextCommon(
                                  controller.orderDetailBean
                                          ?.productDescription ??
                                      "",
                                  size: 24.sp,
                                  lineHeight: 32.sp,
                                  maxLines: 2,
                                ),
                              ),
                              120.widthBox,
                              TextCommon(
                                "共${controller.orderDetailBean?.productNum ?? 1}件",
                                size: 24.sp,
                                lineHeight: 32.sp,
                                color: Color(0xFFA8A8A8),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
          Container(
            width: Get.width,
            margin: MarginPaddingUtil.fromLTRB(
                left: 23, top: 0, right: 17, bottom: 20),
            padding: MarginPaddingUtil.fromLTRB(
                left: 40, top: 35, right: 0, bottom: 48),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(20.radius),
            ),
            child: Column(
              children: [
                Row(
                  children: [
                    TextCommon(
                      "订单编号：",
                      size: 24.sp,
                      lineHeight: 35.sp,
                      color: Color(0xFFA8A8A8),
                    ),
                    20.widthBox,
                    TextCommon(
                      controller.orderDetailBean?.orderNo ?? "",
                      size: 24.sp,
                      lineHeight: 35.sp,
                    ),
                    20.widthBox,
                    ImageCommon(
                      "/icon/copy",
                      size: 20.width,
                    ).addClickEvent(() async {
                      await Clipboard.setData(ClipboardData(
                          text: controller.orderDetailBean?.orderNo ?? ""));
                      ToastUtil.showSuccess("复制成功!");
                    })
                  ],
                ),
                34.heightBox,
                Row(
                  children: [
                    TextCommon(
                      "下单时间：",
                      size: 24.sp,
                      lineHeight: 35.sp,
                      color: Color(0xFFA8A8A8),
                    ),
                    20.widthBox,
                    TextCommon(
                      DateFormat("yyyy-MM-dd HH:mm:ss").format(
                          DateTime.fromMillisecondsSinceEpoch(
                              controller.orderDetailBean?.createTime ?? 0)),
                      size: 24.sp,
                      lineHeight: 35.sp,
                    ),
                    20.widthBox,
                  ],
                ),
                34.heightBox,
                Row(
                  children: [
                    TextCommon(
                      "支付方式：",
                      size: 24.sp,
                      lineHeight: 35.sp,
                      color: Color(0xFFA8A8A8),
                    ),
                    20.widthBox,
                    TextCommon(
                      "酝积分",
                      size: 24.sp,
                      lineHeight: 35.sp,
                    ),
                    20.widthBox,
                  ],
                ),
                34.heightBox,
                Row(
                  children: [
                    TextCommon(
                      "支付时间：",
                      size: 24.sp,
                      lineHeight: 35.sp,
                      color: Color(0xFFA8A8A8),
                    ),
                    20.widthBox,
                    TextCommon(
                      controller.orderDetailBean?.payTime == null
                          ? "未知时间"
                          : DateFormat("yyyy-MM-dd HH:mm:ss").format(
                              DateTime.fromMillisecondsSinceEpoch(
                                  controller.orderDetailBean?.payTime ?? 0)),
                      size: 24.sp,
                      lineHeight: 35.sp,
                    ),
                    20.widthBox,
                  ],
                )
              ],
            ),
          ),
          Container(
            width: Get.width,
            margin: MarginPaddingUtil.fromLTRB(
                left: 23, top: 0, right: 17, bottom: 20),
            padding: MarginPaddingUtil.fromLTRB(
                left: 40, top: 35, right: 0, bottom: 48),
            decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(20.radius),
            ),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                TextCommon(
                  "配送信息",
                  size: 24.sp,
                  lineHeight: 35.sp,
                  fontWeight: FontWeight.bold,
                ),
                20.heightBox,
                Row(
                  children: [
                    TextCommon(
                      "收货信息：",
                      size: 24.sp,
                      lineHeight: 35.sp,
                      color: Color(0xFFA8A8A8),
                    ),
                    20.widthBox,
                    TextCommon(
                      "${controller.orderDetailBean?.recName ?? ""} ${controller.orderDetailBean?.recTel ?? ""}",
                      size: 24.sp,
                      lineHeight: 35.sp,
                    ),
                    20.widthBox,
                  ],
                ),
                12.heightBox,
                Row(
                  children: [
                    Opacity(
                      opacity: 0,
                      child: TextCommon(
                        "下单时间：",
                        size: 24.sp,
                        lineHeight: 35.sp,
                        color: Color(0xFFA8A8A8),
                      ),
                    ),
                    20.widthBox,
                    Expanded(
                      child: TextCommon(
                        "${controller.orderDetailBean?.recAddrBase ?? ""}${controller.orderDetailBean?.recAddrDetail ?? ""}",
                        size: 24.sp,
                        lineHeight: 35.sp,
                        maxLines: 2,
                      ),
                    ),
                    20.widthBox,
                  ],
                ),
                29.heightBox,
                Row(
                  children: [
                    TextCommon(
                      "配送方式：",
                      size: 24.sp,
                      lineHeight: 35.sp,
                      color: Color(0xFFA8A8A8),
                    ),
                    20.widthBox,
                    TextCommon(
                      controller.orderDetailBean?.expressName ?? "",
                      size: 24.sp,
                      lineHeight: 35.sp,
                    ),
                    20.widthBox,
                  ],
                ),
                29.heightBox,
                Row(
                  children: [
                    TextCommon(
                      "快递单号：",
                      size: 24.sp,
                      lineHeight: 35.sp,
                      color: Color(0xFFA8A8A8),
                    ),
                    20.widthBox,
                    TextCommon(
                      controller.orderDetailBean?.expressNo ?? "",
                      size: 24.sp,
                      lineHeight: 35.sp,
                    ),
                    20.widthBox,
                    if (controller.orderDetailBean?.expressNo?.isNotEmpty ??
                        false)
                      ImageCommon(
                        "/icon/copy",
                        size: 20.width,
                      ).addClickEvent(() async {
                        await Clipboard.setData(ClipboardData(
                            text: controller.orderDetailBean?.expressNo ?? ""));
                        ToastUtil.showSuccess("复制成功!");
                      })
                  ],
                ),
              ],
            ),
          ),
          Spacer(),
          Container(
            margin: MarginPaddingUtil.only(bottom: 43),
            padding: MarginPaddingUtil.fromLTRB(
                left: 52, top: 12, right: 60, bottom: 16),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(50),
              border: Border.all(
                color: Color(0xFF414141),
                width: 2.width,
              ),
            ),
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                ImageCommon(
                  "/icon/ic_wuliu",
                  width: 50.width,
                  height: 33.width,
                ),
                22.widthBox,
                TextCommon(
                  "物流追踪",
                  size: 35.sp,
                  lineHeight: 52.sp,
                  fontWeight: FontWeight.bold,
                )
              ],
            ),
          ).addClickEvent(() => Get.to(LogisticsTrackingPage(),arguments: controller.id))
        ],
      ),
    );
  }
}
